home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir40 / np3.zip / NP.ASM next >
Assembly Source File  |  1992-08-04  |  5KB  |  287 lines

  1. ;History:63,1
  2.  
  3. ;  Copyright, 1992, Russell Nelson, <nelson@crynwr.com>
  4.  
  5. ;   This program is free software; you can redistribute it and/or modify
  6. ;   it under the terms of the GNU General Public License as published by
  7. ;   the Free Software Foundation, version 1.
  8. ;
  9. ;   This program is distributed in the hope that it will be useful,
  10. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;   GNU General Public License for more details.
  13. ;
  14. ;   You should have received a copy of the GNU General Public License
  15. ;   along with this program; if not, write to the Free Software
  16. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. HT    equ    09h
  19. CR    equ    0dh
  20. LF    equ    0ah
  21.  
  22. segmoffs    struc            ; defines offs as 0, segm as 2
  23. offs        dw    ?
  24. segm        dw    ?
  25. segmoffs    ends
  26.  
  27. code    segment    public
  28.     assume    cs:code, ds:code
  29.  
  30.     org    100h
  31. start:
  32.     jmp    start_1
  33.  
  34. highest_tsr    dw    0        ;PHD of highest TSR program.
  35. went_tsr    db    0        ;non-zero if a previous cmd went TSR.
  36. first_one    dw    0        ;segment of command's line buffer.
  37. done_one    db    0        ;non-zero if we've printed a program
  38.                     ;  name and hence should skip command.com
  39. command        db    'COMMAND',0    ;name of command.com
  40.  
  41. process_phd:
  42. ;enter with es = segment of a program header.
  43.  
  44. ;
  45. ; Did the previous program go TSR?  If so, remember it as the highest TSR.
  46. ;
  47.     cmp    went_tsr,0
  48.     je    process_phd_1
  49.     mov    highest_tsr,es
  50. process_phd_1:
  51.  
  52. ;
  53. ; Is this one a TSR or not?  If it's below the highest TSR, don't print it.
  54. ;
  55.     cmp    ax,highest_tsr
  56.     jbe    process_phd_7
  57.  
  58. ;
  59. ; If this is COMMAND.COM, don't print [COMMAND] after the program that's
  60. ; spawned it.
  61. ;
  62.     mov    si,offset command
  63.     mov    di,8            ;offset of name in MCB.
  64.     mov    cx,8
  65.     repe    cmpsb
  66.     jne    process_phd_3        ;not COMMAND.COM - go remember that.
  67.  
  68.     xor    al,al            ;get and reset done_one
  69.     xchg    al,done_one
  70.     or    al,al            ;did we just do a program?
  71.     jne    process_phd_7        ;yes, skip printing [COMMAND].
  72.     jmp    short process_phd_4
  73.  
  74. process_phd_3:
  75.  
  76.     inc    done_one        ;remember that we have a program.
  77.  
  78. process_phd_4:
  79.  
  80. ;
  81. ; Print the name found in the MCB.
  82. ;
  83.     mov    dl,'['
  84.     mov    ah,2
  85.     int    21h
  86.     mov    cx,8            ;8 characters max.
  87.     mov    si,8            ;name starts at offset 8.
  88. process_phd_5:
  89.     mov    al,es:[si]
  90.     inc    si
  91.     or    al,al            ;give up when we hit the end.
  92.     je    process_phd_6
  93.     mov    dl,al
  94.     mov    ah,2
  95.     int    21h
  96.     loop    process_phd_5
  97. process_phd_6:
  98.     mov    dl,']'
  99.     mov    ah,2
  100.     int    21h
  101.  
  102. process_phd_7:
  103.     ret
  104.  
  105.  
  106. highest_phd    dw    ?        ;highest PHD we found this time.
  107.  
  108.  
  109. prompt:
  110.     assume    ds:code
  111.  
  112.     cmp    first_one,0        ;do we have command's segment yet?
  113.     jne    prompt_0        ;yes.
  114.     mov    first_one,dx
  115. prompt_0:
  116.     cmp    first_one,dx        ;is this command.com?
  117.     jne    prompt_3        ;no - don't print anything.
  118.  
  119.     mov    done_one,0        ;say that we haven't done any yet.
  120.  
  121. ;
  122. ; Get the first memory block into ES (undocumented).
  123. ;
  124.     mov    ah,52h
  125.     int    21h
  126.     mov    es,es:[bx-2]
  127.  
  128. ;
  129. ; Now we step through the phd's (program headers)
  130. ;
  131.     mov    highest_phd,0
  132. prompt_2:
  133.     cmp    byte ptr es:[0],'M'    ;All but the last block start with 'M'.
  134.     jne    prompt_3
  135.  
  136. ;
  137. ; Is this a PHD?  That is, does it start with CD 20?
  138. ;
  139.     cmp    word ptr es:[16],0cdh + 20h*256
  140.     jne    prompt_4
  141.  
  142. ;
  143. ; Remember the highest PHD we find, in case they removed a TSR.
  144. ;
  145.     mov    ax,es
  146.     cmp    ax,highest_phd
  147.     jbe    process_phd_2
  148.     mov    highest_phd,ax
  149. process_phd_2:
  150.  
  151.     call    process_phd
  152. ;
  153. ; Skip to the next memory block.
  154. ;
  155. prompt_4:
  156.     mov    ax,es            ;add the size of this memory block
  157.     add    ax,es:[3]        ;  to get to the next segment.
  158.     inc    ax
  159.     mov    es,ax
  160.     jmp    prompt_2
  161. prompt_3:
  162. ;
  163. ; Now see if we've removed a TSR.
  164. ;
  165.     mov    ax,highest_phd        ;did they remove a TSR?
  166.     cmp    ax,highest_tsr
  167.     jae    prompt_6
  168.     mov    highest_tsr,ax
  169. prompt_6:
  170.     mov    went_tsr,0        ;Okay, we're done with TSRs.
  171.     ret
  172.  
  173.     assume    ds:nothing
  174.  
  175. their_27 dd    ?            ;remember what their interrupt 27 was.
  176.  
  177. our_27:
  178.     inc    went_tsr
  179.     jmp    their_27
  180.  
  181.  
  182. their_21 dd    ?            ;remember what their interrupt 21 was.
  183.  
  184. our_21:
  185. ;
  186. ; Check for buffered input, and save everything if we've got one.
  187. ;
  188.     cmp    ah,31h            ;TSR call?
  189.     jne    our_21_2
  190.     inc    went_tsr        ;yes - remember it.
  191. our_21_2:
  192.     cmp    ah,0ah            ;buffered input?
  193.     jnz    our_21_1
  194.  
  195.     push    ax
  196.     push    bx            ;save regs
  197.     push    cx
  198.     push    dx
  199.     push    si
  200.     push    di
  201.     push    bp
  202.     push    ds
  203.     push    es
  204.  
  205.     mov    dx,ds            ;remember their buffer's segment in dx.
  206.  
  207.     mov    ax,cs            ;set up ds
  208.     mov    ds,ax
  209.  
  210.     call    prompt
  211.  
  212.     pop    es
  213.     pop    ds
  214.     pop    bp
  215.     pop    di
  216.     pop    si
  217.     pop    dx
  218.     pop    cx
  219.     pop    bx
  220.     pop    ax
  221.  
  222. our_21_1:
  223.     jmp    their_21
  224.  
  225.  
  226. start_1:
  227.     mov    dx,offset copyleft_msg
  228.     mov    ah,9
  229.     int    21h
  230.  
  231. ;
  232. ; Check for MS-LOSS 4.x or greater
  233. ;
  234.     mov    ah,30h
  235.     int    21h
  236.     cmp    al,4
  237.     jae    start_3
  238.     mov    dx,offset bad_ver_msg
  239.     mov    ah,9
  240.     int    21h
  241.     int    20h
  242. start_3:
  243.  
  244. ;
  245. ; Intercept interrupt 21.
  246. ;
  247.     mov    ax,3521h
  248.     int    21h
  249.     mov    their_21.offs,bx
  250.     mov    their_21.segm,es
  251.  
  252.     mov    dx,offset our_21
  253.     mov    ax,2521h
  254.     int    21h
  255. ;
  256. ; Intercept interrupt 27.
  257. ;
  258.     mov    ax,3527h
  259.     int    21h
  260.     mov    their_27.offs,bx
  261.     mov    their_27.segm,es
  262.  
  263.     mov    dx,offset our_27
  264.     mov    ax,2527h
  265.     int    21h
  266. ;
  267. ; and TSR.
  268. ;
  269.     mov    dx,offset start_1+15
  270.     shr    dx,1
  271.     shr    dx,1
  272.     shr    dx,1
  273.     shr    dx,1
  274.     mov    ah,31h
  275.     int    21h
  276.  
  277. copyleft_msg    label    byte
  278.  db "Nosy Prompter v3.0 copyright 1989-1992, Russell Nelson.",CR,LF
  279.  db "This program is free software; see the file COPYING for details.",CR,LF
  280.  db "NO WARRANTY; see the file COPYING for details.",CR,LF,'$'
  281.  
  282. bad_ver_msg    db    "Requires MS-LOSS 4.x or greater$"
  283.  
  284. code    ends
  285.  
  286.     end    start
  287.